<?php
namespace app\admin\service;

use think\Loader;
use app\admin\service\Common;
use app\admin\model\Stock AS StockModel;

class Stock extends Common {

    public function _initialize(){
    }

    public static function Collect($where = [], $arr = []){

        $data = [];
        $data["uuid"] = md5(time().mt_rand(1000,999999999));
        if(!empty($arr["SecurityShortName"])){
            $data["stock_name"] = $arr["SecurityShortName"];
        }
        if(!empty($arr["CodeType"])){
            $data["code_type"] = $arr["CodeType"];
        }
        $data["stock_type"] = 1;
        $data["busines_type"] = !empty($arr['SECURITY_TYPEE']) ? trim($arr['SECURITY_TYPEE']) : '';
        $data["jys"] = $where["jys"];
        $data["status"] = 0;

        $reStock = [];
        $reStock = StockModel::Detail($where, $arr);
        $reStockId = 0;
        if(!empty($reStock)){
            StockModel::where(['sid'=>$reStock['sid']])->update($data);
            $reStockId = $reStock['sid'];
        }else{
            $data["stock_code"] = $arr["SecurityCode"];
            $reStockId = StockModel::insertGetId($data);
        }
        return $reStockId;
    }
}